package asteroids.model.programs.statement;

import java.util.ArrayList;
import java.util.Map;

import asteroids.model.programs.expression.*;
import asteroids.model.programs.type.*;

public class Turn extends Action {

	private E e;
	
	public Turn(int line, int column, E e) {
		super(line, column);
		this.e = e;
	}
	
	public void execute(T type){
		if(type instanceof ShipType){
			T value = e.getValue();
			if(value instanceof DoubleType)
				((ShipType) type).getValue().turn(((DoubleType) value).getValue());
		}
		setExecuted(true);
	}

	public E getExpression(){
		return e;
	}
	
	@Override
	public ArrayList<VariableExpression> getVariableExpressions(){
		return getExpression().getVariables();
	}
	
	public String typecheck(Map<String, T> globals){
		String eTypeCheck = getExpression().typecheck();
		if(!eTypeCheck.equals(""))
			return eTypeCheck;
		T type = getExpression().getValue();
		if(type == null || type.getClass() != DoubleType.class)
			return "Typecast error at line " + getLine() + ", column " + getColumn() + "\n";
		else 
			return "";
	}
}

